Skip to content

Conversation

@eyalkoren
Copy link
Contributor

@eyalkoren eyalkoren commented Apr 24, 2022

What does this PR do?

Closes #2490

Todo

  • Release JUL ECS-logging with public access to tracing metadata updating APIs
  • Release JUL ECS-logging with proper API for additional of custom key/value pairs
  • Use the above in this PR and enable the related unit tests (currently switched off through a method)

Checklist

  • This is a new plugin

@ghost
Copy link

ghost commented Apr 24, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-05-03T15:16:00.382+0000

  • Duration: 46 min 11 sec

Test stats 🧪

Test Results
Failed 0
Passed 2861
Skipped 21
Total 2882

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark tests.

  • run jdk compatibility tests : Run the JDK Compatibility tests.

  • run integration tests : Run the Agent Integration tests.

  • run end-to-end tests : Run the APM-ITs.

  • run windows tests : Build & tests on windows.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@eyalkoren
Copy link
Contributor Author

run integration tests

1 similar comment
@eyalkoren
Copy link
Contributor Author

run integration tests

@eyalkoren eyalkoren marked this pull request as ready for review May 1, 2022 07:42
@github-actions
Copy link

github-actions bot commented May 1, 2022

/test

@SylvainJuge SylvainJuge self-requested a review May 2, 2022 12:42
Copy link
Member

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few questions/comments.


@Override
public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
// todo: change when adding support for instrumentation of Tomcat and JBoss logging
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here for tomcat & jboss logging you mean the logging on those application servers that rely on JUL ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, they rely on it as a framework, but provide their own implementations, for Loggers but also for the actual Handlers, for example - org.apache.juli.FileHandler

return isBootstrapClassLoader();
}

public static class FileReformattingInstrumentation extends JulLogReformattingInstrumentation {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] because the publish method is defined on Handler class, maybe we could have a common method matcher.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't because it will add yet another level to the inheritance hierarchy, making it three-level hierarchy for three instrumentations. I figured it's too much

Comment on lines +47 to +48
private static final ThreadLocal<String> currentPattern = new ThreadLocal<>();
private static final ThreadLocal<Path> currentExampleLogFile = new ThreadLocal<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] is there any reason not to rely on co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent#buildThreadLocal here ? Also, it might be worth checking if we need to have those fields within an @GlobalState.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

co.elastic.apm.agent.sdk.weakconcurrent.WeakConcurrent#buildThreadLocal here ?

There is no need because the value in both cases is basic Java and the this instrumentation is using the bootstrap CL. It is in my todo list to add an asciidoc regarding ThreadLocal and when to use which, it just doesn't get to the top of priorities still...

Also, it might be worth checking if we need to have those fields within an @globalstate

This plugin instruments basic Java types loaded by the bootstrap CL. Why should we require it to be a @GlobalState?

public boolean onAppendEnter(FileHandler fileHandler, String pattern, File exampleLogFile) {
try {
currentPattern.set(pattern);
currentExampleLogFile.set(exampleLogFile.toPath());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[question] here we get the "first file" from the implementation internal state, how do we know that it's representative of all the files that the FileHandler might be writing to ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at java.util.logging.FileHandler#openFiles, you'll see that all files are created based on a single pattern. We only use this for the enclosing log directory. If the user makes the pattern so that directories get changed between logs, that is unexpected and we will just use the first dir. I don't think we need to add special handling for such case, but we can improve based on feedback.

@eyalkoren eyalkoren enabled auto-merge (squash) May 3, 2022 15:16
@eyalkoren eyalkoren merged commit b7f997b into elastic:main May 3, 2022
@eyalkoren eyalkoren deleted the jul-instrumentation branch May 4, 2022 06:12
@SylvainJuge SylvainJuge added await-release Mark issues that depend on next release, or PRs that are planned to be included and removed await-release Mark issues that depend on next release, or PRs that are planned to be included labels May 5, 2022
videnkz pushed a commit to videnkz/apm-agent-java that referenced this pull request May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementing ECS Log reformatting for JUL

2 participants